package ch.zhaw.skuh.turing.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextField;

import ch.zhaw.skuh.turing.controller.Controller;
import ch.zhaw.skuh.turing.model.turingmaschine.TuringChar;

public class OperationButton extends JButton {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4650820106482476533L;
	private Controller controller;
	private TuringChar turing;
	private JTextField field;
	private ControlPanel cp;

	public OperationButton(Controller ctrl, TuringChar turingChar, JTextField fld, ControlPanel controlPanel) {
		super(turingChar.getName());
		this.controller = ctrl;
		this.turing = turingChar;
		this.field = fld;
		this.cp = controlPanel;
		addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String input = field.getText();
				if(turing.validateInput(input)){
					OperationButton ob = (OperationButton) e.getSource();
					cp.setOperationButton(ob);
					controller.initOperation(turing, input);
				}
				
			}
		});
	}

}
